<?php

	set_error_handler(
		create_function(
			'$severity, $message, $file, $line',
			'throw new ErrorException($message, $severity, $severity, $file, $line);'
		)
	);
	
	try{
		if(isset($_GET['id'])){
			$result = file_get_contents("http://172.16.214.1/1dv449/pp222ap/position/producer/". $_GET['id'] . "/json");
		}
		else if(isset($_GET['category'])){
			$result = file_get_contents("http://api.matmarknad.se/categories/json");
		}
		else if(isset($_GET['geo'])){
			$result = file_get_contents("http://api.matmarknad.se/region/json");
		}
		else if(isset($_GET['filter'])){
			$result = file_get_contents("http://api.matmarknad.se/producer/" . $_GET['filter'] . "/json");
		}
		else{
			$result = file_get_contents("http://api.matmarknad.se/producer/json");
		}
		
		echo($result);
	}
	catch(exception $e){
		if(!isset($http_response_header)){
			header('HTTP/1.1 404 Not Found');
			echo('inget server svar');
		}
		else{
			echo('ingen resurs');
		}
	}
	
	restore_error_handler();
	
?>